package com.warm.androidstudy.view.banner.model;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.warm.androidstudy.view.banner.bean.BannerBean;
import com.warm.androidstudy.common.BaseRespon;
import com.warm.androidstudy.common.BaseViewModel;
import com.warm.androidstudy.http.RetrofitManager;
import com.warm.androidstudy.http.RxSchedulers;
import com.warm.androidstudy.service.RetrofitApiService;

import org.jetbrains.annotations.NotNull;

import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class BannerViewModel extends BaseViewModel {
    public BannerViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    private MutableLiveData<List<BannerBean>> liveData = new MutableLiveData<>();
    public void getBanners(){
        RetrofitManager.getInstance()
                .createApi("",RetrofitApiService.class)
                .getBanner()
                .compose(RxSchedulers.applySchedulers())
                .subscribe(new Observer<BaseRespon<List<BannerBean>>>() {
                    @Override
                    public void onSubscribe(@NotNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NotNull BaseRespon<List<BannerBean>> listBaseRespon) {
                        if (listBaseRespon!=null){
                            liveData.setValue(listBaseRespon.getData());
                        }

                    }

                    @Override
                    public void onError(@NotNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    public MutableLiveData<List<BannerBean>> getLiveData() {
        return liveData;
    }
}
